package com.sunda.spmswms.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sunda.spmswms.entity.Whs;
import com.sunda.spmswms.entity.WhsRepackage;
import com.sunda.spmswms.mapper.WhsRepackageMapper;
import com.sunda.spmswms.service.IWhsRepackageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Wayne
 * @since 2021-06-28
 */
@Service
public class WhsRepackageServiceImpl extends ServiceImpl<WhsRepackageMapper, WhsRepackage> implements IWhsRepackageService {

    @Autowired
    WhsRepackageMapper whsRepackageMapper;


    @Override
    public String updateInfo (JSONObject jsonObject) {
        System.out.println(jsonObject);
        JSONArray materialList = jsonObject.getJSONArray("materialList");
        for ( int i = 0 ; i< materialList.size(); i++){
            WhsRepackage whsRepackage = materialList.getJSONObject(i).toJavaObject(WhsRepackage.class);
            whsRepackageMapper.insert(whsRepackage);
        }
        return "success";
    }

    @Override
    public String updateStatus(String billNo){
        whsRepackageMapper.updateStatus(billNo);
        return "success";
    }

    @Override
    public List<String> getHistoryList() {
        return this.baseMapper.selectHistoryList();
    }

    //    public Page<Map<String, Object>> getPageMap(JSONObject doc) {
//        int pageNo = !doc.containsKey("pageNo") || doc.get("pageNo") == null || "".equals(doc.get("pageNo")) ? 1 : Integer.parseInt(doc.get("pageNo").toString());
//        int pageSize = !doc.containsKey("pageSize") || doc.get("pageSize") == null || "".equals(doc.get("pageSize")) ? 20 : Integer.parseInt(doc.get("pageSize").toString());
//
//        Page<Map<String, Object>> pages = new Page<>(pageNo, pageSize);
//        return pages;
//    }
}
